package com.hzhr.iot.user.dao;

import com.hzhr.iot.user.dao.mapper.custom.CompanyEntityCustomMapper;
import com.hzhr.iot.user.dao.mapper.generator.CompanyEntityMapper;
import com.hzhr.iot.user.entity.CompanyEntity;
import com.hzhr.iot.user.entity.ext.CompanyEntityExt;
import com.hzhr.iot.user.queryModel.custom.CompanyCustomQueryModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class CompanyDao {
    @Autowired
    CompanyEntityMapper companyEntityMapper;
    @Autowired
    CompanyEntityCustomMapper companyEntityCustomMapper;

    public int insert(CompanyEntity record) {
        if (record == null) return 0;
        int changeCount = companyEntityMapper.insert(record);
        return changeCount;
    }

    public int delete(CompanyCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int changeCount = companyEntityCustomMapper.delete(queryModel);
        return changeCount;
    }

    public int update(CompanyEntity record) {
        if (record == null) return 0;
        int changeCount = companyEntityMapper.updateByPrimaryKey(record);
        return changeCount;
    }

    public int updateProps(CompanyCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int changeCount = companyEntityCustomMapper.updateProps(queryModel);
        return changeCount;
    }

    public CompanyEntity selectEntity(CompanyCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<CompanyEntityExt> extList = companyEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<CompanyEntity> selectEntityList(CompanyCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<CompanyEntityExt> extList = companyEntityCustomMapper.selectExt(queryModel);
        if (extList == null) return null;
        List<CompanyEntity> entityList = new ArrayList<>();
        for (CompanyEntityExt ext : extList) {
            entityList.add(ext);
        }
        return entityList;
    }
    public CompanyEntityExt selectExt(CompanyCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<CompanyEntityExt> extList = companyEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<CompanyEntityExt> selectExtList(CompanyCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<CompanyEntityExt> extList = companyEntityCustomMapper.selectExt(queryModel);
        return extList;
    }

    public CompanyEntity selectNameEntity(CompanyCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<CompanyEntityExt> extList = companyEntityCustomMapper.selectName(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<CompanyEntity> selectNameEntityList(CompanyCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<CompanyEntityExt> extList = companyEntityCustomMapper.selectName(queryModel);
        if (extList == null) return null;
        List<CompanyEntity> entityList = new ArrayList<>();
        for (CompanyEntityExt ext : extList) {
            entityList.add(ext);
        }
        return entityList;
    }
    public CompanyEntityExt selectNameExt(CompanyCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<CompanyEntityExt> extList = companyEntityCustomMapper.selectName(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<CompanyEntityExt> selectNameExtList(CompanyCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<CompanyEntityExt> extList = companyEntityCustomMapper.selectName(queryModel);
        return extList;
    }

    public int selectCount(CompanyCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int count = companyEntityCustomMapper.selectCount(queryModel);
        return count;
    }
}
